const { DataTypes } = require("Sequelize");
const sequelize = require("./index");

const BorrowModule = sequelize.define(
  "dzl_borrowmodule",
  {
    book_id: {
      type: DataTypes.STRING(255),
      allowNull: false,
      primaryKey: true,
      // validate: {
      //   isEmptyString(value) {
      //     console.log('validate-EmptyString 执行了');
      //     if (value.length <= 0) {
      //       throw new Error('数据为空')
      //     }
      //   },
      // }
    },
    user_id: {
      type: DataTypes.STRING(255),
      allowNull: false,
      primaryKey: true,
    },
    status: {
      type: DataTypes.STRING(2),
      allowNull: false,
    },
  },
  {
    tableName: "borrows",
    timestamps: true,
    createdAt: "borrow_time",
    updatedAt: "return_time",
  }
);

const promise = BorrowModule.sync({ alter: true });
promise.then(
  (success) => {
    console.log("BorrowModule模型同步成功", success);
  },
  (fail) => {
    console.log("BorrowModule模型同步失败", fail);
  }
);

module.exports = BorrowModule;
